package manage.service;

import manage.dao.TeacherDao;
import manage.domain.Teacher;
import manage.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //判断用户输入的Id在学生数组中是否存在对应的学生信息
    public boolean isExists(String id) {
        Teacher[] stus = teacherDao.findAllTeacher();//调用findAllTeacher方法获取所有学生对象
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            Teacher s = stus[i];
            if (s != null && s.getId().equals(id)) {//判断用户输入的id在teacher数组中是否有存在的
                flag = true;
                break;
            }
        }
        return flag;
    }

    //向teacherDao传递想要添加的学生对象
    public boolean addTeacher(Teacher stu) {

        return teacherDao.addTeacher(stu);
    }

    //查找数组中的所有学生信息
    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            Teacher stus = allTeacher[i];
            if (stus != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return allTeacher;
        } else {
            return null;
        }

    }

    //向teacherDao传递用户所想要删除的学生Id
    public void deleteTeacherById(String delId) {
        teacherDao.deleteTeacherById(delId);
    }

    //向teacherDao传递用户要修改的学生信息id和想要修改的学生对象
    public void updateTeacher(String updateId, Teacher newStu) {
        teacherDao.updateTeacher(updateId, newStu);
    }
}
